package models;

import models.constants.DeletedStatus;

import javax.persistence.*;
import java.util.List;

/**
 * Created by liming on 16/7/14.
 */
@Entity
@Table(name = "admin_warehouse")
public class AdminWarehouse extends BaseModel {
    /**
     * 仓库编号
     */
    @Column(name = "code")
    public String code;

    /**
     * 仓库名称
     */
    @Column(name = "name")
    public String name;

    /**
     * 备注
     */
    @Column(name = "remark")
    public String remark;


    /**
     * 逻辑删除,0:未删除，1:已删除
     */
    @Enumerated(EnumType.ORDINAL)
    public DeletedStatus deleted = DeletedStatus.UN_DELETED;

    /**
     * 逻辑删除
     */
    public static void logicDeleteById(long id){
        AdminWarehouse adminWarehouse= AdminWarehouse.findById(id);
        adminWarehouse.deleted = DeletedStatus.DELETED;
        adminWarehouse.save();
    }

    /**
     * 查询所有仓库
     */
    public static List<AdminWarehouse> findAllWarehouse(){
        return AdminWarehouse.find("deleted=?",DeletedStatus.UN_DELETED).fetch();
    }
}
